/**
 * p74/457
 * DOWNLOAD: http://sunsai.googlecode.com/files/SCJPStudyGuide.pdf
 * The rules for overriding a method are as follows:
 * -------------------------------------------------
 * +The argument list must excatly match that of the overridden method.
 * +The return type must be the same as, or subtype of, the return type declared
 *   in the original overridden method in the superclass
 * +The access level cant be more retrictive than the overridden method's
 * +The access level CAN be less restrictive than that of the overridden method.
 * +Instance methods can be overridden only if they are inherited by the subclass.
 *   A subclass within the same package as the instance's superclass can override any
 *   superclass method that not marked PRIVATE/FINAL.
 *   A subclass in different package can override onle those NON-FINAL methods
 *   marked PUBLIC/PROTECTED.
 * +Overriding method CAN throw any unckecked (RUNTIME) exception, regardless of
 *   whether the overridden method declares the exception.
 * +The overriding method must NOT throw checked exceptions that are new or broader
 *   than those declared by overridden by method that declares a FileNotFoundException
 *   cannot be overridden by a method that declares a SQLException, Exception,
 *   or any NON-RUNTIME exception unless it's a subclass of FileNotFoundException.
 * +The overriding method can throw narrower or fewer xceptions. Just because an
 *   overridden method "take riske" doesnt mean that overrding subclass' exception takes
 *   risks.
 *   Bottom line: an overriding method doesnt have to declare any exceptions that it
 *   will never throw, regardless of what the overridden method declared.
 * +You can NOT override a method  marked FINAL.
 * +You can NOT override a method  marked STATIC.
 * +If a method cant be inherited, you cannot override it.
 */

package session2.overridden;

public class Horse extends Animal {

	@Override
	public void eat(Object o) {
		super.eat(o);
		System.out.println("8.Horse.java: eat(Object o)\n");
	}

	public void doStuff() {
		System.out.println("12.Horse.java: doStuff()\n");
	}

	public void buck() {
		System.out.println("Horse.java: buck()");
	}

	public static void main(String arg[]) {
		Horse obj1 = new Horse();
		obj1.eat(obj1);
		obj1.doStuff();

		Animal obj2 = new Animal();
		obj2.eat(obj2);
		System.out.println("obj2.eat(obj2);");
		// ERROR;
		// Reference of Animal class chi "nhin" duoc cac method cua no;
		// obj2.doStuff();

		// Animal reference, Horse object;
		Animal obj3 = new Horse();
		obj3.eat(obj3);
		// ERROR;
		// Reference of Animal class chi "nhin" duoc cac method cua no;
		// obj3.doStuff();

		// Horse obj4 = new Animal();
		// obj4.eat();

		// Horse obj5 = (Horse) new Animal();
		// obj5.eat();

	}

}
